<template>
    <app-layout title="退款申诉">
        <view class="common-form-container explain">
            <view class="textarea-item">
                <view class="title-box">
                    <text>申诉说明</text>
                    <text class="desc">您还可输入{{ maxlength - content.length }}个字</text>
                </view>
                <view class="textarea-box">
                    <textarea
                        v-model="content"
                        :maxlength="maxlength"
                        class="textarea"
                        placeholder="请您详细填写申诉说明"
                        placeholder-class="placeholder-style-3"
                    />
                </view>
            </view>
            <view class="upload-item">
                <block v-for="(item, index) in images" :key="index">
                    <view class="image-box" @click="removeImage(index)">
                        <image class="image" :src="item" mode="aspectFill" />
                    </view>
                </block>
                <view class="image-box upload" @click="chooseImage">
                    <text class="iconfont icon-shangchuantupian"></text>
                    <text class="text">上传图片</text>
                </view>
            </view>
        </view>
        <view class="common-save-form-btn">
            <view class="btn" @click="submit">提交</view>
        </view>
    </app-layout>
</template>

<script>
import AppLayout from "@/components/layout/layout";
export default {
    name: "order-appeal",
    data() {
        return {
            listType: "",
            maxlength: 300,
            id: 0,
            content: "",
            images: [],
        };
    },
    components: {
        AppLayout,
    },
    onLoad(e) {
        if (e.list && e.id && e.id > 0) {
            this.id = e.id;
            this.listType = e.list;
        } else {
            return this.$utils.toast("参数错误").then(() => {
                this.$utils.toPage("", {}, "back");
            });
        }
    },
    onShow() {},
    onReady() {},
    onReachBottom() {},
    onPullDownRefresh() {},
    onShareTimeline() {},
    onShareAppMessage() {},
    methods: {
        /**
         * 删除图片
         */
        removeImage(index) {
            this.images.splice(index, 1);
        },
        /**
         * 上传图片
         */
        chooseImage() {
            this.$utils.chooseImage(8).then((tempFiles) => {
                tempFiles.forEach((item) => {
                    this.$models.system.upload(item.path).then((response) => {
                        this.images.push(response.img);
                    });
                });
            });
        },
        /**
         * 提交
         */
        submit() {
            this.$models.order
                .appealOrder({
                    request: {
                        api: "order.appeal." + this.listType,
                        data: {
                            id: this.id,
                            title: this.content,
                            img: this.images,
                        },
                    },
                })
                .then((response) => {
                    this.$utils.toast(response.msg).then(() => {
                        this.$utils.toPage("", {}, "back");
                    });
                })
                .catch((e) => {
                    this.$utils.toast(e);
                });
        },
    },
};
</script>

<style lang="less" scoped>
.order-id {
    width: 100%;
    box-sizing: border-box;
    background-color: #ffffff;
    .title {
        font-size: 28rpx;
        color: #999999;
    }
}
.order-id {
    padding: 22rpx 40rpx;
    margin-bottom: 18rpx;
    .value {
        font-size: 28rpx;
        color: #000000;
    }
}
.price {
    width: 100%;
    box-sizing: border-box;
    padding: 40rpx;
    margin-bottom: 18rpx;
    background-color: #ffffff;
    .title-box {
        font-size: 28rpx;
        color: #000000;
    }
    .price-box {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-top: 20rpx;
        .number {
            font-size: 48rpx;
            font-weight: bold;
            color: #000000;
        }
    }
    .modify-icon {
        display: flex;
        align-items: center;
        flex-direction: column;
        .iconfont {
            font-size: 46rpx;
            color: #999999;
        }
        .text {
            display: inline-block;
            font-size: 24rpx;
            color: #999999;
            margin-top: 6rpx;
        }
    }
}
.common-form-container.explain {
    width: 100%;
    margin-top: 0;
    .textarea-item {
        padding: 30rpx 40rpx;
        .title-box {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .desc {
            font-size: 24rpx;
            color: #999999;
        }
        .textarea-box {
            border: 0;
        }
        .textarea {
            width: 100%;
            padding: 20rpx 0;
            font-style: 28rpx;
        }
    }
    .upload-item {
        padding: 0 40rpx 30rpx 40rpx;
    }
}
.price-box {
    .submit-price {
        width: 100%;
        height: 68rpx;
        background: #7286f1;
        text-align: center;
        line-height: 68rpx;
        font-size: 32rpx;
        color: #ffffff;
    }
    .price-input {
        display: flex;
        justify-content: space-between;
        margin: 35rpx 0 50rpx 0;
        line-height: 72rpx;
        .input-box {
            display: flex;
        }
        .input {
            width: 450rpx;
            height: 72rpx;
            border: 2rpx solid #d8d8d8;
            box-sizing: border-box;
            padding: 4rpx;
            font-size: 30rpx;
            font-weight: bold;
            color: #000000;
            text-align: center;
        }
        .iconfont {
            margin-left: 18rpx;
        }
    }
}
</style>